Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 702)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 12.99512 12.99316 12.99122 12.98932 12.98743 12.98557 12.98373 12.98191
## [9] 12.98010 12.97831 12.97653 12.97475 12.97298 12.97121 12.96945 12.96768
## [17] 12.96591 12.96413 12.96234 12.96054 12.95873 12.95690 12.95506 12.95319
## [25] 12.95130 12.94938 12.94744 12.94546 12.94345 12.94141 12.93933 12.93721
## [33] 12.93505 12.93284 12.93058 12.92828 12.92591 12.92347 12.92096 12.91839
## [41] 12.91576 12.91309 12.91037 12.90762 12.90484 12.90203 12.89920 12.89636
## [49] 12.89352 12.89067 12.88782 12.88499 12.88217 12.87938 12.87662 12.87389
## [57] 12.87120 12.86856 12.86597 12.86344 12.86097 12.85858 12.85626 12.85402
## [65] 12.85187 12.84982 12.84786 12.84602 12.84428 12.84267 12.84117 12.83959
## [73] 12.83769 12.83550 12.83304 12.83033 12.82738 12.82421 12.82083 12.81727
## [81] 12.81354 12.80966 12.80565 12.80153 12.79730 12.79300 12.78863 12.78422
## [89] 12.77978 12.77534 12.77089 12.76648 12.76210 12.75779 12.75355 12.74941
## [97] 12.74539 12.74149 12.73774 12.73415 12.73075 12.72755 12.72456 12.72181
## [105] 12.71932 12.71709 12.71515 12.71352 12.71221 12.71124 12.71063 12.71039
## [113] 12.71055 12.71108 12.71196 12.71316 12.71468 12.71650 12.71861 12.72100
## [121] 12.72366 12.72656 12.72971 12.73307 12.73666 12.74044 12.74441 12.74856
## [129] 12.75287 12.75732 12.76192 12.76663 12.77146 12.77639 12.78140 12.78649
## [137] 12.79163 12.79682 12.80204 12.80729 12.81386 12.82288 12.83412 12.84733
## [145] 12.86225 12.87864 12.89625 12.91484 12.93415 12.95394 12.97395 12.99395
## [153] 13.01369 13.03291 13.05137 13.06882 13.08501 13.09969 13.11262 13.12356
## [161] 13.13224 13.14066 13.15084 13.16257 13.17563 13.18982 13.20493 13.22073
## [169] 13.23703 13.25361 13.27026 13.28677 13.30293 13.31853 13.33335 13.34719
## [177] 13.35983 13.37107 13.38069 13.38849 13.39424 13.39775 13.40008 13.40240
## [185] 13.40467 13.40685 13.40889 13.41074 13.41236 13.41369 13.41470 13.41533
## [193] 13.41555 13.41529 13.41453 13.41320 13.41128 13.40870 13.40542 13.40139
## [201] 13.39658 13.39093 13.38439 13.37693 13.36849 13.35903 13.34849 13.33685
## [209] 13.32404 13.31002 13.29336 13.27295 13.24928 13.22282 13.19402 13.16336
## [217] 13.13132 13.09836 13.06495 13.03157 12.99867 12.96674 12.93624 12.90765
## [225] 12.88143 12.85805 12.83442 12.80739 12.77732 12.74459 12.70956 12.67261
## [233] 12.63412 12.59444 12.55395 12.51302 12.47202 12.43132 12.39130 12.35232
## [241] 12.31475 12.27897 12.24534 12.21424 12.18604 12.16110 12.13980 12.12125
## [249] 12.10421 12.08856 12.07419 12.06097 12.04879 12.03752 12.02704 12.01724
## [257] 12.00798 11.99916 11.99065 11.98232 11.97407 11.96576 11.95729 11.94852
## [265] 11.93934 11.92962 11.92085 11.91445 11.91017 11.90778 11.90705 11.90775
## [273] 11.90964 11.91249 11.91607 11.92013 11.92446 11.92882 11.93296 11.93667
## [281] 11.93970 11.94183 11.94282 11.94243 11.94044 11.93660 11.93070 11.92409
## [289] 11.91824 11.91303 11.90834 11.90404 11.90002 11.89617 11.89235 11.88845
## [297] 11.88436 11.87995 11.87510 11.86970 11.86362 11.85675 11.84896 11.83985
## [305] 11.82917 11.81710 11.80379 11.78940 11.77411 11.75808 11.74146 11.72442
## [313] 11.70712 11.68973 11.67241 11.65533 11.63864 11.62250 11.60709 11.59257
## [321] 11.57909 11.56682 11.55593 11.54658 11.53642 11.52329 11.50760 11.48974
## [329] 11.47013 11.44917 11.42726 11.40482 11.38224 11.35993 11.33830 11.31775
## [337] 11.29869 11.28153 11.26666 11.25451 11.24546 11.23992 11.23831 11.23942
## [345] 11.24173 11.24519 11.24976 11.25540 11.26205 11.26967 11.27821 11.28763
## [353] 11.29788 11.30891 11.32067 11.33312 11.34621 11.35990 11.37413 11.38886
## [361] 11.40405 11.41964 11.43560 11.45186 11.47019 11.49211 11.51730 11.54541
## [369] 11.57609 11.60901 11.64381 11.68016 11.71772 11.75613 11.79505 11.83415
## [377] 11.87308 11.91150 11.94906 11.98541 12.02023 12.05316 12.08385 12.11198
## [385] 12.13719 12.16244 12.19067 12.22154 12.25468 12.28974 12.32638 12.36422
## [393] 12.40293 12.44214 12.48150 12.52066 12.55925 12.59694 12.63335 12.66815
## [401] 12.70097 12.73145 12.75925 12.78401 12.80538 12.82300 12.83862 12.85418
## [409] 12.86958 12.88471 12.89949 12.91381 12.92757 12.94068 12.95304 12.96454
## [417] 12.97510 12.98462 12.99298 13.00011 13.00590 13.01024 13.01231 13.01150
## [425] 13.00804 13.00218 12.99416 12.98423 12.97262 12.95958 12.94535 12.93017
## [433] 12.91429 12.89795 12.88139 12.86485 12.84858 12.83281 12.81780 12.80378
## [441] 12.79099 12.77968 12.77009 12.75982 12.74656 12.73065 12.71242 12.69222
## [449] 12.67039 12.64727 12.62320 12.59852 12.57359 12.54873 12.52429 12.50062
## [457] 12.47804 12.45691 12.43757 12.42036 12.40562 12.39369 12.38292 12.37148
## [465] 12.35949 12.34704 12.33423 12.32116 12.30793 12.29463 12.28138 12.26825
## [473] 12.25537 12.24281 12.23069 12.21911 12.20816 12.19794 12.18855 12.18009
## [481] 12.17266 12.16636 12.16129 12.15706 12.15322 12.14979 12.14678 12.14421
## [489] 12.14208 12.14042 12.13923 12.13854 12.13835 12.13868 12.13954 12.14095
## [497] 12.14292 12.14547 12.14860 12.15300 12.15921 12.16712 12.17658 12.18746
## [505] 12.19963 12.21294 12.22726 12.24246 12.25839 12.27493 12.29194 12.30928
## [513] 12.32681 12.34441 12.36193 12.37924 12.39620 12.41268 12.42855 12.44365
## [521] 12.45787 12.47106 12.48309 12.49383 12.50313 12.51306 12.52556 12.54033
## [529] 12.55706 12.57542 12.59512 12.61584 12.63726 12.65908 12.68099 12.70268
## [537] 12.72383 12.74413 12.76327 12.78094 12.79683 12.81063 12.82202 12.83070
## [545] 12.83635 12.83867 12.83898 12.83880 12.83814 12.83697 12.83529 12.83308
## [553] 12.83034 12.82705 12.82321 12.81880 12.81382 12.80824 12.80206 12.79528
## [561] 12.78787 12.77983 12.77115 12.76181 12.75181 12.74114 12.72978 12.71772
## [569] 12.70495 12.68953 12.66982 12.64630 12.61943 12.58969 12.55753 12.52344
## [577] 12.48788 12.45131 12.41421 12.37705 12.34030 12.30442 12.26989 12.23716
## [585] 12.20673 12.17904 12.15457 12.13379 12.11330 12.08963 12.06314 12.03422
## [593] 12.00324 11.97057 11.93658 11.90165 11.86615 11.83046 11.79495 11.75999
## [601] 11.72595 11.69321 11.66215 11.63313 11.60653 11.58273 11.56209 11.54499
## [609] 11.53180 11.52167 11.51339 11.50679 11.50172 11.49804 11.49559 11.49420
## [617] 11.49374 11.49403 11.49494 11.49630 11.49796 11.49977 11.50157 11.50320
## [625] 11.50453 11.50659 11.51045 11.51598 11.52302 11.53144 11.54110 11.55184
## [633] 11.56354 11.57604 11.58920 11.60288 11.61694 11.63124 11.64563 11.65997
## [641] 11.67411 11.68792 11.70126 11.71397 11.72592 11.73696 11.74792 11.75967
## [649] 11.77217 11.78536 11.79917 11.81357 11.82849 11.84388 11.85969 11.87585
## [657] 11.89232 11.90903 11.92595 11.94300 11.96014 11.97731 11.99446 12.01153
## [665] 12.02846 12.04552 12.06297 12.08080 12.09901 12.11757 12.13647 12.15571
## [673] 12.17526 12.19512 12.21527 12.23570 12.25639 12.27733 12.29851 12.31991
## [681] 12.34153 12.36334 12.38534 12.40751 12.42983 12.45230 12.47486 12.49747
## [689] 12.52016 12.54293 12.56582 12.58883 12.61200 12.63534 12.65887 12.68261
## [697] 12.70659 12.73081 12.75530 12.78008 12.80518 12.83060
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 702)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.62192 12.61753 12.61324 12.60904 12.60494 12.60093 12.59701 12.59317
## [9] 12.58943 12.58576 12.58218 12.57868 12.57526 12.57192 12.56865 12.56546
## [17] 12.56233 12.55928 12.55629 12.55337 12.55052 12.54772 12.54499 12.54232
## [25] 12.53970 12.53713 12.53462 12.53216 12.52975 12.52739 12.52507 12.52280
## [33] 12.52057 12.51838 12.51622 12.51410 12.51200 12.50990 12.50781 12.50573
## [41] 12.50367 12.50162 12.49961 12.49763 12.49569 12.49379 12.49194 12.49014
## [49] 12.48841 12.48674 12.48514 12.48361 12.48217 12.48081 12.47954 12.47837
## [57] 12.47730 12.47634 12.47549 12.47476 12.47415 12.47367 12.47333 12.47312
## [65] 12.47306 12.47314 12.47339 12.47379 12.47435 12.47509 12.47600 12.47705
## [73] 12.47818 12.47939 12.48068 12.48206 12.48352 12.48507 12.48671 12.48843
## [81] 12.49025 12.49215 12.49414 12.49622 12.49839 12.50066 12.50301 12.50546
## [89] 12.50801 12.51064 12.51338 12.51621 12.51913 12.52216 12.52528 12.52850
## [97] 12.53182 12.53524 12.53876 12.54238 12.54611 12.54993 12.55387 12.55790
## [105] 12.56204 12.56629 12.57065 12.57511 12.57968 12.58435 12.58914 12.59404
## [113] 12.59905 12.60409 12.60910 12.61407 12.61902 12.62396 12.62889 12.63381
## [121] 12.63875 12.64370 12.64867 12.65367 12.65870 12.66378 12.66892 12.67411
## [129] 12.67937 12.68470 12.69011 12.69562 12.70122 12.70692 12.71274 12.71974
## [137] 12.72884 12.73984 12.75253 12.76671 12.78217 12.79870 12.81609 12.83414
## [145] 12.85265 12.87140 12.89018 12.90880 12.92704 12.94471 12.96158 12.97745
## [153] 12.99213 13.00539 13.01704 13.02687 13.03744 13.05121 13.06776 13.08670
## [161] 13.10764 13.13017 13.15390 13.17843 13.20337 13.22831 13.25286 13.27662
## [169] 13.29919 13.32017 13.33917 13.35578 13.36962 13.38028 13.38737 13.39227
## [177] 13.39663 13.40044 13.40370 13.40640 13.40853 13.41008 13.41105 13.41142
## [185] 13.41119 13.41035 13.40889 13.40681 13.40410 13.40075 13.39674 13.39208
## [193] 13.38676 13.38076 13.37408 13.36672 13.35865 13.34989 13.34041 13.33021
## [201] 13.31929 13.30763 13.29522 13.28206 13.26815 13.25174 13.23141 13.20758
## [209] 13.18069 13.15115 13.11941 13.08589 13.05102 13.01523 12.97895 12.94261
## [217] 12.90664 12.87148 12.83754 12.80526 12.77507 12.74740 12.72268 12.70134
## [225] 12.68047 12.65706 12.63141 12.60380 12.57453 12.54388 12.51214 12.47960
## [233] 12.44656 12.41329 12.38009 12.34725 12.31506 12.28381 12.25378 12.22526
## [241] 12.19855 12.17394 12.15171 12.13214 12.11555 12.10125 12.08834 12.07668
## [249] 12.06614 12.05661 12.04794 12.04003 12.03273 12.02593 12.01950 12.01330
## [257] 12.00723 12.00114 11.99492 11.98843 11.98155 11.97615 11.97396 11.97466
## [265] 11.97794 11.98347 11.99095 12.00005 12.01045 12.02184 12.03390 12.04632
## [273] 12.05877 12.07094 12.08250 12.09315 12.10257 12.11043 12.11642 12.12023
## [281] 12.12153 12.12000 12.11763 12.11646 12.11634 12.11709 12.11855 12.12055
## [289] 12.12292 12.12550 12.12812 12.13060 12.13278 12.13450 12.13557 12.13585
## [297] 12.13515 12.13332 12.13018 12.12556 12.11930 12.11093 12.10024 12.08746
## [305] 12.07281 12.05651 12.03880 12.01989 12.00000 11.97938 11.95823 11.93678
## [313] 11.91526 11.89390 11.87291 11.85252 11.83295 11.81444 11.79720 11.78146
## [321] 11.76744 11.75537 11.74216 11.72496 11.70441 11.68111 11.65570 11.62878
## [329] 11.60098 11.57292 11.54522 11.51849 11.49335 11.47042 11.45033 11.43369
## [337] 11.42112 11.41325 11.40794 11.40271 11.39764 11.39280 11.38825 11.38407
## [345] 11.38032 11.37709 11.37443 11.37242 11.37113 11.37063 11.37100 11.37229
## [353] 11.37459 11.37796 11.38247 11.38820 11.39521 11.40358 11.41337 11.42572
## [361] 11.44150 11.46040 11.48211 11.50633 11.53274 11.56104 11.59091 11.62205
## [369] 11.65415 11.68689 11.71997 11.75309 11.78592 11.81816 11.84951 11.87965
## [377] 11.90827 11.93506 11.95972 11.98193 12.00430 12.02943 12.05701 12.08674
## [385] 12.11832 12.15143 12.18579 12.22107 12.25698 12.29321 12.32947 12.36543
## [393] 12.40080 12.43528 12.46856 12.50034 12.53030 12.55815 12.58359 12.60630
## [401] 12.62599 12.64459 12.66414 12.68447 12.70539 12.72672 12.74829 12.76993
## [409] 12.79145 12.81268 12.83343 12.85354 12.87282 12.89110 12.90819 12.92393
## [417] 12.93814 12.95063 12.96122 12.96975 12.97642 12.98161 12.98540 12.98787
## [425] 12.98910 12.98916 12.98815 12.98613 12.98319 12.97941 12.97486 12.96963
## [433] 12.96380 12.95745 12.95066 12.94350 12.93605 12.92841 12.92064 12.91282
## [441] 12.90505 12.89527 12.88172 12.86490 12.84530 12.82339 12.79969 12.77467
## [449] 12.74882 12.72264 12.69661 12.67123 12.64698 12.62435 12.60384 12.58594
## [457] 12.57112 12.55679 12.54017 12.52153 12.50116 12.47931 12.45627 12.43231
## [465] 12.40769 12.38270 12.35759 12.33266 12.30816 12.28437 12.26157 12.24002
## [473] 12.22000 12.20177 12.18562 12.17182 12.16063 12.15233 12.14521 12.13747
## [481] 12.12924 12.12066 12.11186 12.10298 12.09416 12.08554 12.07724 12.06941
## [489] 12.06219 12.05571 12.05010 12.04550 12.04206 12.03990 12.03916 12.03998
## [497] 12.04250 12.04715 12.05416 12.06336 12.07454 12.08752 12.10213 12.11817
## [505] 12.13545 12.15380 12.17301 12.19292 12.21333 12.23405 12.25490 12.27569
## [513] 12.29625 12.31637 12.33587 12.35458 12.37230 12.38884 12.40402 12.41766
## [521] 12.43306 12.45328 12.47771 12.50579 12.53691 12.57049 12.60595 12.64269
## [529] 12.68014 12.71770 12.75478 12.79081 12.82518 12.85732 12.88664 12.91254
## [537] 12.93445 12.95177 12.96393 12.97328 12.98258 12.99176 13.00078 13.00958
## [545] 13.01810 13.02631 13.03415 13.04155 13.04848 13.05489 13.06071 13.06589
## [553] 13.07039 13.07416 13.07714 13.07927 13.08051 13.08081 13.08011 13.07836
## [561] 13.07552 13.07152 13.06631 13.05985 13.05208 13.04295 13.03241 13.01900
## [569] 13.00162 12.98076 12.95693 12.93061 12.90229 12.87248 12.84167 12.81034
## [577] 12.77900 12.74813 12.71824 12.68981 12.66333 12.63932 12.61824 12.59649
## [585] 12.57040 12.54044 12.50706 12.47072 12.43187 12.39098 12.34849 12.30488
## [593] 12.26060 12.21609 12.17183 12.12827 12.08587 12.04508 12.00636 11.97017
## [601] 11.93697 11.90722 11.88136 11.85987 11.83998 11.81879 11.79653 11.77345
## [609] 11.74977 11.72572 11.70155 11.67748 11.65375 11.63059 11.60824 11.58694
## [617] 11.56691 11.54839 11.53161 11.51681 11.50422 11.49408 11.48662 11.48153
## [625] 11.47828 11.47674 11.47680 11.47833 11.48121 11.48532 11.49055 11.49676
## [633] 11.50385 11.51168 11.52015 11.52912 11.53848 11.54811 11.55789 11.56769
## [641] 11.57740 11.58689 11.59605 11.60475 11.61373 11.62377 11.63480 11.64676
## [649] 11.65959 11.67324 11.68763 11.70272 11.71844 11.73473 11.75153 11.76878
## [657] 11.78642 11.80439 11.82262 11.84106 11.85994 11.87951 11.89976 11.92069
## [665] 11.94229 11.96454 11.98745 12.01099 12.03516 12.05995 12.08536 12.11136
## [673] 12.13796 12.16515 12.19291 12.22124 12.25013 12.27956 12.30954 12.34004
## [681] 12.37107 12.40260 12.43465 12.46718 12.50020 12.53370 12.56760 12.60185
## [689] 12.63648 12.67150 12.70693 12.74279 12.77911 12.81590 12.85319 12.89099
## [697] 12.92933 12.96822 13.00769 13.04775 13.08843 13.12975
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 702)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 11.98249 11.97937 11.97632 11.97331 11.97036 11.96746 11.96461 11.96180
## [9] 11.95902 11.95629 11.95358 11.95091 11.94827 11.94564 11.94305 11.94047
## [17] 11.93790 11.93535 11.93280 11.93027 11.92773 11.92520 11.92266 11.92012
## [25] 11.91756 11.91500 11.91242 11.90982 11.90720 11.90456 11.90189 11.89919
## [33] 11.89646 11.89369 11.89088 11.88802 11.88513 11.88218 11.87918 11.87613
## [41] 11.87302 11.86985 11.86662 11.86328 11.85982 11.85625 11.85257 11.84880
## [49] 11.84496 11.84104 11.83707 11.83306 11.82902 11.82495 11.82088 11.81681
## [57] 11.81276 11.80873 11.80474 11.80080 11.79693 11.79312 11.78941 11.78579
## [65] 11.78228 11.77889 11.77564 11.77252 11.76957 11.76678 11.76418 11.76176
## [73] 11.75955 11.75755 11.75578 11.75425 11.75297 11.75195 11.75088 11.74948
## [81] 11.74776 11.74574 11.74347 11.74095 11.73822 11.73530 11.73222 11.72900
## [89] 11.72567 11.72226 11.71878 11.71527 11.71175 11.70824 11.70478 11.70138
## [97] 11.69808 11.69490 11.69185 11.68898 11.68631 11.68385 11.68164 11.67970
## [105] 11.67806 11.67674 11.67576 11.67517 11.67497 11.67519 11.67587 11.67702
## [113] 11.67868 11.68086 11.68359 11.68690 11.69082 11.69536 11.70056 11.70644
## [121] 11.71350 11.72215 11.73225 11.74366 11.75625 11.76988 11.78443 11.79974
## [129] 11.81569 11.83215 11.84897 11.86602 11.88318 11.90029 11.91723 11.93386
## [137] 11.95005 11.96566 11.98056 11.99461 12.00994 12.02858 12.05018 12.07441
## [145] 12.10095 12.12947 12.15963 12.19111 12.22358 12.25670 12.29015 12.32359
## [153] 12.35670 12.38915 12.42061 12.45073 12.47921 12.50570 12.52988 12.55142
## [161] 12.56998 12.58793 12.60770 12.62905 12.65173 12.67550 12.70012 12.72533
## [169] 12.75091 12.77660 12.80216 12.82735 12.85193 12.87564 12.89826 12.91953
## [177] 12.93921 12.95706 12.97284 12.98630 12.99719 13.00528 13.01152 13.01701
## [185] 13.02175 13.02574 13.02895 13.03140 13.03307 13.03395 13.03404 13.03333
## [193] 13.03181 13.02948 13.02633 13.02236 13.01755 13.01190 13.00541 12.99806
## [201] 12.98985 12.98077 12.97082 12.95999 12.94827 12.93566 12.92215 12.90772
## [209] 12.89239 12.87613 12.85626 12.83063 12.80000 12.76516 12.72689 12.68595
## [217] 12.64313 12.59920 12.55493 12.51112 12.46852 12.42793 12.39011 12.35584
## [225] 12.32590 12.30107 12.27775 12.25201 12.22413 12.19440 12.16309 12.13049
## [233] 12.09687 12.06252 12.02771 11.99273 11.95786 11.92337 11.88955 11.85668
## [241] 11.82503 11.79489 11.76655 11.74027 11.71634 11.69504 11.67665 11.66059
## [249] 11.64602 11.63279 11.62079 11.60988 11.59994 11.59084 11.58244 11.57463
## [257] 11.56726 11.56022 11.55337 11.54658 11.53973 11.53269 11.52533 11.51752
## [265] 11.50912 11.50002 11.49218 11.48743 11.48547 11.48599 11.48867 11.49320
## [273] 11.49929 11.50661 11.51486 11.52372 11.53289 11.54205 11.55091 11.55913
## [281] 11.56643 11.57248 11.57698 11.57961 11.58007 11.57805 11.57323 11.56682
## [289] 11.56022 11.55347 11.54656 11.53953 11.53239 11.52516 11.51784 11.51047
## [297] 11.50306 11.49563 11.48818 11.48075 11.47335 11.46599 11.45870 11.44979
## [305] 11.43780 11.42304 11.40585 11.38655 11.36546 11.34292 11.31925 11.29477
## [313] 11.26982 11.24471 11.21978 11.19535 11.17175 11.14930 11.12833 11.10916
## [321] 11.09213 11.07755 11.06576 11.05708 11.04943 11.04064 11.03092 11.02047
## [329] 11.00949 10.99818 10.98674 10.97538 10.96430 10.95370 10.94378 10.93475
## [337] 10.92680 10.92014 10.91498 10.91150 10.90992 10.91044 10.91325 10.91842
## [345] 10.92574 10.93506 10.94622 10.95906 10.97341 10.98911 11.00601 11.02393
## [353] 11.04272 11.06222 11.08227 11.10270 11.12335 11.14407 11.16468 11.18504
## [361] 11.20497 11.22432 11.24292 11.26062 11.27918 11.30030 11.32374 11.34923
## [369] 11.37654 11.40540 11.43557 11.46679 11.49880 11.53136 11.56422 11.59712
## [377] 11.62980 11.66202 11.69353 11.72407 11.75338 11.78122 11.80734 11.83147
## [385] 11.85338 11.87485 11.89774 11.92186 11.94703 11.97306 11.99977 12.02697
## [393] 12.05449 12.08215 12.10974 12.13710 12.16404 12.19037 12.21592 12.24049
## [401] 12.26391 12.28600 12.30655 12.32541 12.34237 12.35727 12.37153 12.38662
## [409] 12.40233 12.41848 12.43486 12.45131 12.46761 12.48358 12.49903 12.51377
## [417] 12.52760 12.54034 12.55179 12.56176 12.57006 12.57650 12.58092 12.58338
## [425] 12.58404 12.58304 12.58055 12.57671 12.57168 12.56560 12.55863 12.55092
## [433] 12.54262 12.53389 12.52487 12.51572 12.50660 12.49764 12.48901 12.48085
## [441] 12.47333 12.46658 12.46077 12.45436 12.44587 12.43553 12.42356 12.41017
## [449] 12.39559 12.38004 12.36373 12.34690 12.32976 12.31253 12.29543 12.27869
## [457] 12.26252 12.24714 12.23278 12.21966 12.20799 12.19800 12.18834 12.17760
## [465] 12.16591 12.15338 12.14015 12.12635 12.11210 12.09754 12.08277 12.06794
## [473] 12.05317 12.03859 12.02432 12.01049 11.99723 11.98466 11.97292 11.96212
## [481] 11.95240 11.94388 11.93669 11.92964 11.92161 11.91278 11.90338 11.89361
## [489] 11.88367 11.87376 11.86410 11.85488 11.84632 11.83861 11.83197 11.82659
## [497] 11.82270 11.82048 11.82014 11.82143 11.82389 11.82746 11.83207 11.83766
## [505] 11.84416 11.85150 11.85961 11.86844 11.87790 11.88795 11.89850 11.90950
## [513] 11.92088 11.93257 11.94450 11.95661 11.96883 11.98109 11.99334 12.00549
## [521] 12.01750 12.02928 12.04077 12.05191 12.06263 12.07495 12.09068 12.10945
## [529] 12.13088 12.15459 12.18020 12.20735 12.23564 12.26471 12.29418 12.32366
## [537] 12.35279 12.38119 12.40847 12.43427 12.45821 12.47990 12.49897 12.51505
## [545] 12.52775 12.53670 12.54389 12.55148 12.55939 12.56752 12.57580 12.58413
## [553] 12.59243 12.60060 12.60857 12.61624 12.62352 12.63033 12.63658 12.64219
## [561] 12.64705 12.65109 12.65422 12.65635 12.65740 12.65727 12.65587 12.65313
## [569] 12.64895 12.64234 12.63259 12.62000 12.60490 12.58761 12.56844 12.54770
## [577] 12.52572 12.50282 12.47930 12.45549 12.43171 12.40826 12.38547 12.36366
## [585] 12.34314 12.32423 12.30724 12.29250 12.27713 12.25832 12.23643 12.21184
## [593] 12.18491 12.15602 12.12553 12.09383 12.06127 12.02824 11.99510 11.96223
## [601] 11.92999 11.89875 11.86890 11.84080 11.81481 11.79132 11.77069 11.75329
## [609] 11.73950 11.72770 11.71605 11.70462 11.69347 11.68267 11.67228 11.66235
## [617] 11.65295 11.64415 11.63601 11.62858 11.62194 11.61614 11.61125 11.60732
## [625] 11.60443 11.60289 11.60291 11.60438 11.60716 11.61114 11.61619 11.62221
## [633] 11.62906 11.63663 11.64480 11.65345 11.66245 11.67169 11.68104 11.69039
## [641] 11.69961 11.70859 11.71721 11.72534 11.73286 11.73966 11.74636 11.75367
## [649] 11.76155 11.76998 11.77892 11.78833 11.79820 11.80849 11.81917 11.83021
## [657] 11.84157 11.85323 11.86516 11.87733 11.88970 11.90224 11.91493 11.92774
## [665] 11.94062 11.95374 11.96725 11.98115 11.99543 12.01007 12.02508 12.04043
## [673] 12.05613 12.07216 12.08851 12.10518 12.12215 12.13942 12.15698 12.17482
## [681] 12.19292 12.21129 12.22991 12.24877 12.26786 12.28718 12.30668 12.32635
## [689] 12.34619 12.36622 12.38645 12.40690 12.42757 12.44848 12.46965 12.49108
## [697] 12.51279 12.53480 12.55711 12.57973 12.60269 12.62599
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")